<div class="row-fluid">
<header>
	Edit Attendance
</header>
<h2>Select </h2>
<table class="table table-condensed" width="100%">
	<tr>
	<?php if($this->ion_auth->is_admin()){?>	
		<th>User Name <span class="red">*</span></th>
		<?php }?>
		<th>Date to Change <span class="red">*</span></th>
		<td></td>
	</tr>
	<tr>
	<?php if($this->ion_auth->is_admin()){?>	
	<td>		
	<select class="chzn-select" name="user" id="user">
		<option value="">
			Select User
		</option>
		<?php
		foreach($users as $user)
		{
			?>
			<option value="<?= $user->id?>">
				<?= $user->username?>
			</option>
			<?php
		}?>
	</select>
	<?php } else {?>
	<input type="hidden" name="user" id="user" value="<?= $this->session->userdata('user_id');?>"/>
	<?php }?>
	</td>
		<td><input type="text" class="datepicker" name="date" id="date" /></td>
		<td><input type="submit" value="search database" class="btn btn-success" id="search"/>
	</td></tr>
</table>
</div>
<div>
<h2>Update Time</h2>
<table class="table">
	<tr>
	<td><input  type="text" value="" id="entry_time"/></td>
	<td><input  type="submit" value="update entry time" class="btn" id="update_entry"/></td>
	</tr>
	<tr>
	<td><input  type="text" value="" id="exit_time"/></td>
	<td><input  type="submit" value="update exit time" class="btn"  id="update_exit"/></td>
	</tr>
	</table>
</div>

<script type="text/javascript">
	<!--
	$("#search").click(function()
		{			
			var user = $("#user").val();			
			var date_id = $("#date").val();
			$('#loading-overlay').show();
			$('#loading').show();
			$.post('<?= site_url('user/attendance/get_particular_attendance');?>',
				{
					user_id : user,date_id:date_id
				}, function(msg)
				{
					$('#loading-overlay').hide();
					$('#loading').hide();
					var m = msg
					var get_val = m.split(',');
					$('#entry_time').val(get_val[0]);
					$('#exit_time').val(get_val[1]);
				})
		})
		
	
	$("#update_entry").click(function()
		{
			//alert("hello");
			var user = $("#user").val();
			var date_id = $("#date").val();
			var entry_time = $("#entry_time").val();
			//alert(user);
			if($("#user").val()=='')
			{
				alert("Field Cannot be empty")
				return false;
			}
			$('#loading-overlay').show();
			$('#loading').show();
			$.post('<?= site_url('user/attendance/update_entry_time');?>',
				{
					user_id : user,date_id:date_id,entry_time:entry_time
				}, function(time)
				{
					//alert(time)
				$('#loading-overlay').hide();
				$('#loading').hide();
				$('#entry_time').val(time);
				alert("Entry Time Has been update");
				})
		})
		
		$("#update_exit").click(function()
		{
			//alert("hello");
			var user = $("#user").val();
			var date_id = $("#date").val();
			var exit_time = $("#exit_time").val();
			//alert(user);
			$('#loading-overlay').show();
			$('#loading').show();
			$.post('<?= site_url('user/attendance/update_exit_time');?>',
				{
					user_id : user,date_id:date_id,exit_time:exit_time
				}, function(time)
				{
				$('#loading-overlay').hide();
				$('#loading').hide();
				$('#exit_time').val(time);
				alert("Exit Time Has been update");
				})
		})
		
	//-->
</script>

